package org.leon.controller;

import org.leon.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/email")
public class EmailController {

    private EmailService emailService;

    @Autowired
    public EmailController(EmailService emailService) {
        this.emailService = emailService;
    }

    /**
     * 给指定邮箱发送验证码
     * @return true/false
     */
    @PostMapping("/{email}/{code}")
    public Boolean sendEmail(@PathVariable String email, @PathVariable String code) {
        try {
            emailService.sendMail(email, code);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

}
